#ifndef QXGAME_CHARACTER_H
#define QXGAME_CHARACTER_H

#include <memory>
#include "Object.h"
#include "GameAnimation.h"
#include "SDL_mixer.h"

class Character : public Object {
public:
    Character();
    ~Character() override = default;

    void OnUpdate(double delta) override;
    void OnRender() override;
    bool CanRemove() override;
    void IncreaseHp(double value);
    void DecreaseHp(double value);
    void IncreaseMp(double value);
    void DecreaseMp(double value);
    std::pair<GameVector, GameShape> GetAttackPosition();

    virtual void ResetStatus();
    virtual void Attack();
    virtual void OnAttack(const std::vector<std::shared_ptr<Character>> &characters);
    virtual void Die();
    virtual void OnDie();
    virtual void Rigidity();
    virtual void OnRigidity();
    virtual void ReleaseSkill(uint16_t idx);

private:
    void UpdateMove(double delta);

public:
    double hp = 0;
    double maxHp = 0;
    double recoverHp = 0;
    double mp = 0;
    double maxMp = 0;
    double recoverMp = 0;
    double damage = 0;
    double speed = 0;
    double maxSpeed = 0;
    double viewRange = 200;   // 视野范围

    GameTimer recoverTimer;
    GameTimer rigidityTimer;
    std::atomic<bool> canRigidity = true;
    std::atomic<bool> isRigidity = false;
    std::atomic<bool> isAttack = false;
    std::atomic<bool> isDie = false;
    std::atomic<bool> isMoving[Facing::SIZE] = {false};

    GameVector velocity;
    GameVector direction;
    GameShape attackShape;  // 攻击的碰撞体积

    GameAnimation animStandBy[Facing::SIZE];
    GameAnimation animWalk[Facing::SIZE];
    GameAnimation animAttack[Facing::SIZE];
    GameAnimation animDie[Facing::SIZE];
    GameAnimation animRigidity[Facing::SIZE];
    GameAnimation *animCurrent = &animStandBy[Facing::Down];

    Mix_Chunk *attackMix = nullptr;
    Mix_Chunk *dieMix = nullptr;
};


#endif // QXGAME_CHARACTER_H
